package javase.javase02.networkprograming;

import java.io.*;
import java.net.Socket;


/**
 * @author: Gan
 * @date 2021/4/23 0023 19:18
 * @description:客户端 1.客户端键盘录入，服务器输出文本文件
 **/
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        // 创建一个流套接字并将其连接到指定 IP 地址的指定端口号。
        Socket socket = new Socket("127.0.0.1", 3309);
        //键盘录入数据
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream out = socket.getOutputStream();
        //客户端写
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
        String line;
        while ((line = br.readLine()) != null) {
            bw.write(line);
            bw.newLine();
            bw.flush();
        }
        bw.close();
        br.close();
        socket.close();
    }
}
